package pub.wkq.springboot.web;


import java.util.HashMap;
import java.util.Map;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import pub.wkq.springboot.pojo.Ingredient;
import pub.wkq.springboot.repository.IngredientRepository;

import static pub.wkq.springboot.pojo.Ingredient.*;


/**
 * @author 王开琦
 */
@Component
public class IngredientByIdConverter implements Converter<String, Ingredient> {
    private final IngredientRepository ingredientRepository;

    private Map<String, Ingredient> ingredientMap = new HashMap<>();

    public IngredientByIdConverter(IngredientRepository ingredientRepository) {
        this.ingredientRepository = ingredientRepository;

    }

    @Override
    public Ingredient convert(String id) {
        return ingredientRepository.findById(id).orElse(null);
    }

}